<template>
	<view class="mainpadding" style="padding-bottom: 150rpx;" v-if="pageShow">
		<view class="flexleft">
			<view class="labletext xiaohuang margin_right" v-if="dataAll.task_category_id!=1">{{dataAll.taskcategory.name}}/{{dataAll.carattr.name}}</view>
			<view class="labletext xiaohuang margin_right" v-if="dataAll.task_category_id==1">其他</view>
			<!-- 状态:1=待领取,2=平台待指定,3=进行中,4=待审核,5=已完成，6任务终止 -->
			<view class="titletext hei_text bold" v-if="dataAll.status==1">待领取</view>
			<view class="titletext hei_text bold" v-if="dataAll.status==2">平台待指定</view>
			<view class="titletext hei_text bold" v-if="dataAll.status==3">进行中</view>
			<view class="titletext hei_text bold" v-if="dataAll.status==4">待审核</view>
			<view class="titletext hei_text bold" v-if="dataAll.status==5">已完成</view>
			<view class="titletext hei_text bold" v-if="dataAll.status==6">任务终止</view>
		</view>
		<view class="mainpadding_top ffffff radius">
			<view class="flexbetween xiahuaxian">
				<view class="titletext hei_text bold">{{dataAll.tasktime_text}}</view>
				<view class="xiaohong bold titletext">{{dataAll.score}}</view>
			</view>
			<view class="flexbetween margin_top" v-if="dataAll.start_address">
				<view class="xiankuan" style="width: 500rpx;">
					<text class="lvdian margin_right2"></text>
					<text class="xiaolv main_size margin_right2">距你{{returnKmUnit(Number(dataAll.distance1))}}</text>
					<text class="xiaohei main_size margin_right2">{{dataAll.start_address}}</text>
				</view>
				<view class="daohang" @click="openmap(1,dataAll)"></view>
			</view>
			<view class="flexbetween margin_top" v-if="dataAll.end_address">
				<view class="xiankuan" style="width: 500rpx;">
					<text class="huangdian margin_right2"></text>
					<text class="xiaohuang main_size margin_right2">距你{{returnKmUnit(Number(dataAll.distance2))}}</text>
					<text class="xiaohei main_size margin_right2">{{dataAll.end_address}}</text>
				</view>
				<view class="daohang" @click="openmap(2,dataAll)"></view>
			</view>
			<view class="xiankuan margin_top" style="width: 500rpx;">
				<text class="landian margin_right2"></text>
				<text class="xiaolan main_size margin_right2">{{dataAll.name}}</text>
				<text class="xiaohei main_size margin_right2" v-show="dataAll.task_category_id!=1">航班/车次：{{dataAll.carno}}</text>
			</view>
		</view>
		<view class="mainpadding_top ffffff radius" v-if="dataAll.taskitem.length">
			<view class="titletext hei_text bold">任务要求</view>
			<view class="" v-for="ite in dataAll.taskitem" :key="ite.id">
				<view class="main_size xiaohui margin_top">{{ite.name}}</view>
				<view class="flexleft flex_wrap">
					<view class="itemimgBox flexcenter margin_top2" v-for="(it,index) in ite.images_text" @click="lbtpriview(index,ite.images_text)">
						<view class="listleftimg">
							<image class="listleftimg radius" :src="it" mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="mainpadding_top ffffff radius">
			<view class="flexbetween">
				<view class="main_size xiaohei bold">订单编号</view>
				<view class="main_size xiaohui">{{dataAll.order_no}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="main_size xiaohei bold">收益</view>
				<view class="main_size xiaohuang">{{dataAll.score}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="main_size xiaohei bold">任务时间</view>
				<view class="main_size xiaohui">{{dataAll.tasktime_text}}</view>
			</view>
			<view class="flexbetween margin_top" v-if="dataAll.jdtime_text">
				<view class="main_size xiaohei bold">接单时间</view>
				<view class="main_size xiaohui">{{dataAll.jdtime_text}}</view>
			</view>
			<view class="flexbetween margin_top" v-if="dataAll.status==4 || dataAll.status==5">
				<view class="main_size xiaohei bold">审核上传</view>
				<view class="main_size xiaohui">{{dataAll.applyuploadtime_text}}</view>
			</view>
			<view class="flexleft flex_wrap" v-if="dataAll.status==4 || dataAll.status==5">
				<view class="itemimgBox flexcenter margin_top" v-for="(it,index) in dataAll.apply_images_text" @click="lbtpriview(index,dataAll.apply_images_text)">
					<view class="listleftimg">
						<image class="listleftimg radius" :src="it" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<view class="gudingdb mainpadding ffffff">
			<view class="flexbetween">
				<view class="flexcolumn" @click.stop="callphone(dataAll.mobile)">
					<u-icon name="phone" color="#333" size="20"></u-icon>
					<view class="xiaohui main_size">客户	</view>
				</view>
				<!-- 状态:1=待领取,2=平台待指定,3=进行中,4=待审核,5=已完成 -->
				<view class="bigbtn" style="width: 85%;" v-if="dataAll.status==1" @click.stop="showModal('是否确认接取任务？')">接取任务</view>
				<view class="bigbtn" style="width: 85%;" v-if="dataAll.status==3 && dataAll.task_category_id!=1" @click.stop="showModal('是否确认完成任务？')">确认完成</view>
				<view class="bigbtn" style="width: 85%;" v-if="dataAll.status==3 && dataAll.task_category_id==1" @click.stop="show=true;">提交审核</view>
				<view class="bigbtn" style="width: 85%;background-color: #bbbbbb;" v-if="dataAll.status==4" >正在审核中</view>
			</view>
		</view>
		<u-modal :show="show" title="拍照上传" confirmColor="#ff8506" confirmText="确认" @confirm="upconfirm"cancelText="取消"
			@cancel="show=false" showCancelButton>
			<view class="slot-content" style="width: 730rpx;">
				
				<view class="flexleft flex_wrap">
					<view class="itemimgBox flexcenter margin_top2" v-for="(item,index) in images_text" :key="index">
						<!-- 已上传 -->
						<view class="listleftimg">
							<image class="listleftimg radius" :src="item" mode=""></image>
							<view class="deleteimg"@click="delindex(index,images,images_text)"></view>
						</view>
					</view>
					<view class="itemimgBox flexcenter margin_top2" @click="uploadImg(3,images,images_text)"
						v-if="images.length<3">
						<!-- 未上传 -->
						<image class="listleftimg radius" src="../static/images/system/upimg.png" mode=""></image>
					</view>
				</view>
			</view>
		</u-modal>
		<moDal :message="modal" @modalSure="modalSure" @modalcancel="modalcancel"></moDal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				modal:{
					modalShow:false,
					title:"",
				},
				images_text:[],
				images:[],
				show:false,
				lat:"",
				lng:"",
				dataAll:{},
				pageShow:false,
				listid:""
			}
		},
		onLoad(options) {
			this.listid = options.id
			// #ifdef APP-PLUS
			this.getLocation()
			// #endif
			// #ifdef H5
			this.getDetail()
			// #endif
		},
		methods: {
			showModal(val){
				this.modal.title = val
				this.modal.modalShow = true
			},
			modalSure(){
				if(this.modal.title=="是否确认接取任务？"){
					this.jiequorder()
				}else if(this.modal.title=="是否确认完成任务？"){
					this.wancheng()
				}
				this.modalcancel()
			},
			modalcancel(){
				this.modal.modalShow = false
			},
			jiequorder(){
				httpRequest.request('/api/taskcl/getTask', 'GET', {
					id: this.listid,
				}).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.getDetail()
					}
				})
			},
			wancheng(){
				httpRequest.request('/api/taskcl/submitApply', 'GET', {
					id: this.listid,
					apply_images:""
				}).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.getDetail()
					}
				})
			},
			getLocation() {
				let _this = this
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						uni.hideLoading()
						console.log(res, "获取定位成功");
						_this.lat = res.latitude
						_this.lng = res.longitude
						_this.getDetail()
					},
					fail(err) {
						uni.hideLoading()
					}
				});
			},
			getDetail(){
				httpRequest.request('/api/taskcl/taskDetail', 'GET', {
					id: this.listid,
					lat:this.lat,
					lng:this.lng,
				}).then(res => {
					if(res.code==1){
						this.dataAll = res.data
						this.pageShow = true
					}else{
						httpRequest.toast(res.msg)
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
					
				})
			},
			upconfirm(){
				this.show = false
				uni.showLoading({
					mask:true,
					title:"上传中"
				})
				httpRequest.request('/api/taskcl/submitApply', 'GET', {
					id: this.listid,
					apply_images:this.images.join()
				}).then(res => {
					uni.hideLoading()
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.images = []
						this.images_text = []
						this.getDetail()
					}
				})
			},
			uploadImg(value, upImgs, upImgs_text) { //上传图片
				let _this = this;
				let num = Number(value) - upImgs.length;
				if (num <= 0) {
					return false;
				}
				httpRequest.chooseImage(num, ['camera']).then(res => {
					for (var i = 0; i < res.length; i++) {
						_this.uploadImageService(res[i], upImgs, upImgs_text)
					}
				}).catch(err => {});
			},
			delindex(index, upImg, upImgs_text) {
				upImg.splice(index, 1)
				upImgs_text.splice(index, 1)
			},
			uploadImageService(url, upImg, upImgs_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					upImg.push(res.url)
					upImgs_text.push(image_item);
				}).catch(err => {});
			},
			openmap(val,item){
				if(val==1){
					uni.openLocation({
					     latitude: Number(item.start_latitude),//即将传到高德或腾讯地图的终点纬度  必须是数值，字符串无效
					     longitude:Number(item.start_longitude),//即将传到高德或腾讯地图的终点经度  必须是数值，字符串无效
					     name: item.start_address,//即将传到高德或腾讯地图的店铺名称
					     address: item.start_address,//即将传到高德或腾讯地图的详细地址
					     scale: 18
					})
				}else{
					uni.openLocation({
					     latitude: Number(item.end_latitude),//即将传到高德或腾讯地图的终点纬度  必须是数值，字符串无效
					     longitude:Number(item.end_longitude),//即将传到高德或腾讯地图的终点经度  必须是数值，字符串无效
					     name: item.end_address,//即将传到高德或腾讯地图的店铺名称
					     address: item.end_address,//即将传到高德或腾讯地图的详细地址
					     scale: 18
					})
				}
				
			}
		}
	}
</script>

<style>
.listleftimg{
	width: 160rpx;
	height: 160rpx;	
	min-width: 160rpx;
	position: relative;
}
</style>
